package com.gt.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gt.app.domain.EsLifeCases;
import com.gt.app.domain.EsUserBaseInfo;
import com.gt.app.mapper.EsUserBaseInfoMapper;
import com.gt.app.service.EsLifeCasesService;
import com.gt.app.service.EsUserBaseInfoService;
import com.gt.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 个人基本信息 服务实现类
 * </p>
 *
 * @author caidesheng
 */
@Slf4j
@Service
public class EsUserBaseInfoServiceImpl extends ServiceImpl<EsUserBaseInfoMapper, EsUserBaseInfo> implements EsUserBaseInfoService {

    @Override
    public void add(EsUserBaseInfo esUserBaseInfo) {
        esUserBaseInfo.setUserId(SecurityUtils.getUserId());
        LambdaQueryWrapper<EsUserBaseInfo> wrapper = new LambdaQueryWrapper<EsUserBaseInfo>().eq(EsUserBaseInfo::getUserId, SecurityUtils.getUserId());
        EsUserBaseInfo userBaseInfo = this.getOne(wrapper);
        if (userBaseInfo != null) {
            this.remove(wrapper);
            this.save(esUserBaseInfo);
            return;
        }
        this.save(esUserBaseInfo);
    }

    @Override
    public EsUserBaseInfo getUserBaseInfo() {
        LambdaQueryWrapper<EsUserBaseInfo> wrapper = new LambdaQueryWrapper<EsUserBaseInfo>().eq(EsUserBaseInfo::getUserId, SecurityUtils.getUserId());
        EsUserBaseInfo userBaseInfo = this.getOne(wrapper);
        return userBaseInfo;
    }
}
